package com.x.thoth.app;

import com.x.thoth.cache.autoconfiguration.ehcache.XEhCacheHandler;
import com.x.thoth.cache.autoconfiguration.ehcache.XEhCacheManager;
import com.x.thoth.cache.autoconfiguration.redis.XRedisCacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.Cache;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@SpringBootApplication
@RestController
@EnableCaching
public class AppApplication {


    @Autowired
    private XEhCacheManager ehCacheManager;

    @Autowired
    private XRedisCacheManager xRedisCacheManager;

    @Autowired
    private PersonService personService;

    public static void main(String[] args) {
        SpringApplication.run(AppApplication.class, args);
    }

    @GetMapping("test")
    public List<Person> test(@RequestParam("param") String test) {
        XEhCacheHandler ehCacheHandler = new XEhCacheHandler("SYSTEM-CONFIG", ehCacheManager);
        if (test.equals("clear")) {
            ehCacheHandler.clear();
        }
        return personService.queryString("param");
    }

    @GetMapping("select")
    public void query() {
        Cache cache = ehCacheManager.getCache("SYSTEM-CONFIG");
    }
}
